home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 27 / CU Amiga Magazine's Super CD-ROM 27 (1998)(EMAP Images)(GB)[!][issue 1998-10].iso / CUCD / Programming / JForth / JTools / Demos / demo_strip < prev    next >
Encoding:
Text File  |  1991-12-30  |  2.5 KB  |  112 lines

  1. \ Strip Chart Demo - For data display applications.
  2. \
  3. \ Author: Phil Burk
  4. \ Copyright 1986  Delta Research
  5.  
  6. include? gr.init ju:amiga_graph
  7. include? ev.getclass ju:amiga_events
  8. include? choose ju:random
  9.  
  10. ANEW TASK-DEMO_STRIP
  11.  
  12. \ Example of accessing AMIGA structure.
  13. : WINDOW_MAX_X ( -- w , access window structure for x limits )
  14.     gr-curwindow @ ..@ wd_width
  15. ;
  16.  
  17. : WINDOW_MAX_Y ( -- h , access window structure for y limits )
  18.     gr-curwindow @ ..@ wd_height
  19. ;
  20.  
  21. \ Variables for tracking curtain position.
  22. VARIABLE STRIP-MIN-X
  23. VARIABLE STRIP-MAX-X
  24. VARIABLE STRIP-MIN-Y
  25. VARIABLE STRIP-MAX-Y
  26. 30 strip-min-y !
  27. 90 strip-max-y !
  28. 100 strip-min-x !
  29.  
  30. VARIABLE ST-PREVIOUS-X
  31. VARIABLE ST-PREVIOUS-Y
  32.  
  33. : STRIP.CLEAR.FRONT ( width xpos -- , clear pen area)
  34.     0 gr.color!
  35.     ( 1+) dup rot +   strip-min-y @ swap  strip-max-y @  gr.rect
  36.     1 gr.color!
  37. ;
  38.  
  39. : STRIP.DRAW  ( y -- , draw a new data point )
  40.     st-previous-x @
  41.     16 over strip.clear.front   ( clear area around pen )
  42.     3 + dup strip-max-x @ >  ( wrap around? )
  43.     IF drop strip-min-x @ dup  st-previous-x !
  44.         swap gr.move
  45.     ELSE ( -- y x+2 )
  46.         1 gr.color!
  47.         dup st-previous-x !
  48.         swap 2dup gr.draw   ( draw trace )
  49.         over 16 + strip-min-y @ strip-max-y @ + 2/ gr.move
  50.         3 gr.color!         ( draw pen )
  51.         gr.draw
  52.     THEN
  53. ;
  54.  
  55. : BAR.DRAW ( y -- , draw simple bar chart )
  56.     >r 0 gr.color!
  57.     20 strip-min-y @ 50 r@ gr.rect  ( draw black portion )
  58. \
  59.     3 gr.color!
  60.     20 r> 50 strip-max-y @ gr.rect    ( draw data portion )
  61. ;
  62.  
  63. : MAKEUP.STRIP ( -- , draw one cycle of the strip chart )
  64.     st-previous-y @   7 choose 3 -  +  ( random walk to fake data )
  65.     strip-min-y @ max  strip-max-y @ min  ( clip to rect )
  66.     dup st-previous-y !
  67.     dup strip.draw
  68.     bar.draw
  69. ;
  70.  
  71. strip-min-x @ st-previous-x !
  72. strip-min-y @ st-previous-y !
  73.  
  74. : DEMO.STRIP ( -- ,
  75.     2 gr.color! 0 0 window_max_x window_max_y
  76.     gr.rect
  77.     1 gr.color!
  78.     50 20 " JForth - Stripchart" gr.xytext
  79.     strip-min-x @ strip-min-y @ gr.move
  80.     BEGIN
  81.         20 0
  82.         DO  makeup.strip
  83.         LOOP
  84.         ?closebox
  85.     UNTIL
  86. ;
  87.  
  88. NewWindow NewStrip   ( Create a template for the new window. )
  89.  
  90. : STRIP.OPEN  ( -- window | NULL )
  91.     gr.init
  92.     NewStrip NewWindow.Setup   ( Set defaults for window )
  93. \
  94. \ The address of the title string must be converted to absolute
  95. \ addressing for use by the Amiga operating System.
  96.     0" Stripchart!" >abs NewStrip ..! nw_title ( change title )
  97. \
  98. \ Create window from template and make it the current window.
  99.     NewStrip gr.opencurw
  100.     window_max_x 60 - strip-max-x !
  101. ;
  102.  
  103. : STRIP  ( -- , Demonstrate stripchart. )
  104.     strip.open
  105.     IF  demo.strip
  106.         gr.closecurw
  107.     THEN
  108.     gr.term
  109. ;
  110.  
  111. cr ." Enter:   STRIP     for demo!" cr
  112.